package com.guigu.userservice.controller;

import com.google.protobuf.ServiceException;
import com.guigu.userservice.dto.OperationLogDto;
import com.guigu.userservice.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 操作日志表（记录操作员的所有系统操作，用于审计和问题排查） 前端控制器
 * </p>
 *
 * @author zcy
 * @since 2025-09-28
 */
@RestController
@RequestMapping("/user/operationLog")
public class OperationLogController {
    @Autowired
    private OperationLogService operationLogService;

    /**
     * 添加操作日志
     * @param operationLogDto
     */
    @PostMapping("/addOperationLog")
    public void addOperationLog(@RequestBody OperationLogDto operationLogDto, HttpServletRequest request) throws ServiceException {
        operationLogDto.setOperationIp(request.getRequestURI().substring(1));
        operationLogService.insertOperationLog(operationLogDto);
    }

}
